package cn.ymjr.business.service.impl;

import cn.ymjr.business.constants.SurnameConstants;
import cn.ymjr.business.dao.*;
import cn.ymjr.business.entity.*;
import cn.ymjr.business.form.ExplainForm;
import cn.ymjr.business.form.OrderForm;
import cn.ymjr.business.form.StartForm;
import cn.ymjr.business.service.BusinessService;
import cn.ymjr.customer.dao.SysCustomerMapper;
import cn.ymjr.customer.entity.SysCustomer;
import cn.ymjr.sys.config.exception.BusinessException;
import cn.ymjr.sys.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author Tiny
 * @create 2022/4/1 17:54
 */
@Service
public class BusinessServiceImpl implements BusinessService {
    private final Logger logger = Logger.getLogger(getClass());
    @Autowired
    private SysCustomerMapper customerMapper;
    @Autowired
    private SysExplainMapper explainMapper;
    @Autowired
    private SysActivityMapper activityMapper;
    @Autowired
    private SysGoodsMapper sysGoodsMapper;
    @Autowired
    private SysInformationMapper informationMapper;
    @Autowired
    private SysUserStarMapper userStarMapper;
    @Autowired
    private SysUserAddressMapper addressMapper;
    @Autowired
    private SysOrderMapper orderMapper;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private SysConstantMapper constantMapper;

    @Override
    public Result nameExplain(ExplainForm explainForm, String token) throws BusinessException {
        SysCustomer customer = customerMapper.selectByPrimaryKey(explainForm.getUserId());
        if(customer==null || StringUtils.isEmpty(customer.getMobile())){
            throw new BusinessException("请授权");
        }
        if(!token.equals(MD5Util.encode(customer.getMobile()))){
            throw new BusinessException("登录失效，请登录");
        }
        if(StringUtils.isEmpty(explainForm.getName()) || explainForm.getName().length() <2){
            throw new BusinessException("请输入正确的姓名");
        }
        customer.setExplainCount(customer.getExplainCount()+1);
        customerMapper.updateByPrimaryKeySelective(customer);
        String name = explainForm.getName();
        if(name.length()==2){
           return executeTwoWord(name);
        }else if(name.length()==3){
            return executeThreeWord(name);
        }else if(name.length()==4){
            return executeFourthWord(name);
        }
        return new Result(false,"暂不支持的名字类型，敬请期待");
    }

    @Override
    public Result activityList(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        PageHelper.orderBy("create_time desc");
        List<SysActivity> activities = activityMapper.selectAll();
        return new Result(new PageInfo<>(activities));
    }

    @Override
    public Result activityDetail(Integer id) {
        SysActivity activity = activityMapper.findById(id);
        return new Result(activity);
    }

    @Override
    public Result goodsCategory() {
        Map<String,String> result = new HashMap<>();
        List<SysConstant> category = constantMapper.findByCode("goods_category");
        for (SysConstant sysConstant : category) {
            result.put(sysConstant.getConstantName(),sysConstant.getConstantValue());
        }
        return new Result(result);
    }

    @Override
    public Result goodsList(Integer page, Integer pageSize, Integer category) {
        SysGoods sysGoods = new SysGoods();
        sysGoods.setCategory(category);
        PageHelper.startPage(page, pageSize);
        PageHelper.orderBy("create_time desc");
        List<SysGoods> goodsList = sysGoodsMapper.select(sysGoods);
        return new Result(new PageInfo<>(goodsList));
    }

    @Override
    public Result goodsDetail(Integer id) {
        SysGoods sysGoods = sysGoodsMapper.selectByPrimaryKey(id);
        Map<String, String> goodsUnit = DictInit.constantMap.get("goods_unit");
        sysGoods.setGoodsUnit(goodsUnit.get(sysGoods.getGoodsUnit()));
        return new Result(sysGoods);
    }

    @Override
    public Result informationList(Integer page, Integer pageSize,Integer userId,Integer category) {
        Map<Integer,Integer> need = new HashMap<>();
        if(userId!=null){
            List<SysUserStar> stars = userStarMapper.selectByUser(userId);
            for (SysUserStar star : stars) {
                need.put(star.getInfoId(),star.getId());
            }
        }
        PageHelper.startPage(page, pageSize);
        List<SysInformation> info = informationMapper.findAll(category);
        PageInfo<SysInformation> pageInfo = new PageInfo<>(info);
        for (SysInformation sysInformation : pageInfo.getList()) {
            if(need.get(sysInformation.getId())!=null){
                sysInformation.setStar(true);
            }
        }
        return new Result(pageInfo);
    }

    @Override
    public Result infoDetail(Integer id) {
        SysInformation sysInformation = informationMapper.selectByPrimaryKey(id);
        return new Result(sysInformation);
    }

    @Override
    public Result editAddress(SysUserAddress sysUserAddress, String token)throws BusinessException {
        SysCustomer customer = customerMapper.selectByPrimaryKey(sysUserAddress.getUserId());
        if(customer==null || StringUtils.isEmpty(customer.getMobile())){
            throw new BusinessException("请授权");
        }
        if(!token.equals(MD5Util.encode(customer.getMobile()))){
            throw new BusinessException("登录失效，请登录");
        }
        List<SysUserAddress> list = addressMapper.selectByUserId(sysUserAddress.getUserId());
        if(sysUserAddress.getId()==null){
            sysUserAddress.setCreateTime(DateUtil.getSNowDateTime());
            sysUserAddress.setIsDelete(0);
            if(list.size()==0){
                sysUserAddress.setIsDefault(1);
            }else{
                if(sysUserAddress.getIsDefault()==1){
                    addressMapper.cleanDefault(sysUserAddress.getUserId());
                }
            }
            addressMapper.insertUseGeneratedKeys(sysUserAddress);
            return new Result(true,"添加成功");
        }else{
            if(list.size()==0){
                sysUserAddress.setIsDefault(1);
            }else{
                if(sysUserAddress.getIsDefault()==1){
                    addressMapper.cleanDefault(sysUserAddress.getUserId());
                }
            }
            addressMapper.updateByPrimaryKeySelective(sysUserAddress);
            return new Result(true,"修改成功");
        }
    }

    @Override
    public Result addressList(Integer userId, Integer page, Integer pageSize, String token)throws BusinessException {
        SysCustomer customer = customerMapper.selectByPrimaryKey(userId);
        if(customer==null || StringUtils.isEmpty(customer.getMobile())){
            throw new BusinessException("请授权");
        }
        if(!token.equals(MD5Util.encode(customer.getMobile()))){
            throw new BusinessException("登录失效，请登录");
        }
        PageHelper.startPage(page, pageSize);
        List<SysUserAddress> addressList = addressMapper.findPage(userId);
        return new Result(new PageInfo<>(addressList));
    }

    @Override
    public Result orderList(Integer userId, Integer page, Integer pageSize, Integer orderStatus) {
        PageHelper.startPage(page, pageSize);
        List<SysOrder> list = orderMapper.findPage(userId,orderStatus);
        return new Result(new PageInfo<>(list));
    }

    @Override
    public Result submitOrder(OrderForm orderForm, String token) throws BusinessException {
        SysCustomer customer = customerMapper.selectByPrimaryKey(orderForm.getUserId());
        if(customer==null || StringUtils.isEmpty(customer.getMobile())){
            throw new BusinessException("请授权");
        }
        if(!token.equals(MD5Util.encode(customer.getMobile()))){
            throw new BusinessException("登录失效，请登录");
        }
        SysGoods sysGoods = sysGoodsMapper.selectByPrimaryKey(orderForm.getGoodsId());
        if(sysGoods==null){
            throw new BusinessException("请选择购买的商品");
        }
        SysUserAddress address = addressMapper.selectByPrimaryKey(orderForm.getAddressId());
        SysOrder sysOrder = new SysOrder();
        sysOrder.setOrderNo(getOrderNo());
        sysOrder.setOrderStatus(1);
        sysOrder.setGoodsId(orderForm.getGoodsId());
        sysOrder.setUserId(orderForm.getUserId());
        sysOrder.setOrderPrice(sysGoods.getGoodsPrice());
        sysOrder.setConstantName(address.getConstantName());
        sysOrder.setConstantPhone(address.getConstantPhone());
        sysOrder.setAddress(address.getProvinceName()+address.getCityName()+address.getRegionName()+address.getDetail());
        sysOrder.setCreateTime(DateUtil.getSNowDateTime());
        sysOrder.setIsDelete(0);
        orderMapper.insertUseGeneratedKeys(sysOrder);
        return new Result(sysOrder);
    }

    @Override
    public Result orderPay(Integer orderId, String token, HttpServletRequest request)throws BusinessException {
        SysOrder sysOrder = orderMapper.selectByPrimaryKey(orderId);
        if(sysOrder.getOrderStatus() == 1){
            SysCustomer customer = customerMapper.selectByPrimaryKey(sysOrder.getUserId());
            if(!token.equals(MD5Util.encode(customer.getMobile()))){
                throw new BusinessException("登录失效，请登录");
            }
            Map<String, String> map = WxPayUtil.weixinPrePay(sysOrder.getOrderNo(), new BigDecimal(sysOrder.getOrderPrice()),
                    "订单支付", customer.getOpenId(), request);
            if(map.get("result_code").equalsIgnoreCase("success")) {
                SortedMap<String, Object> parameterMap = new TreeMap<>();
                long stamp = System.currentTimeMillis();
                parameterMap.put("appId", map.get("appid"));
                parameterMap.put("timeStamp", stamp+"");
                parameterMap.put("nonceStr", map.get("nonce_str"));
                parameterMap.put("package", "prepay_id=" + map.get("prepay_id"));
                parameterMap.put("signType", "MD5");
                String sign = PayCommonUtil.createSign(parameterMap);

                Map result = new HashMap();
                result.put("timeStamp", stamp+"");
                result.put("nonceStr", map.get("nonce_str"));
                result.put("package", "prepay_id=" + map.get("prepay_id"));
                result.put("signType", "MD5");
                result.put("paySign", sign);
                return new Result(result);
            }else{
                return new Result(false,"调取微信支付失败");
            }
        }
        return new Result(false,"订单状态有误");
    }

    @Override
    public Result ensureOrder(Integer userId, Integer orderId, String token) throws BusinessException {
        SysOrder sysOrder = orderMapper.selectByPrimaryKey(orderId);
        if(sysOrder.getOrderStatus()==3){
            SysCustomer customer = customerMapper.selectByPrimaryKey(userId);
            if(customer==null || StringUtils.isEmpty(customer.getMobile())){
                throw new BusinessException("请授权");
            }
            if(!token.equals(MD5Util.encode(customer.getMobile()))){
                throw new BusinessException("登录失效，请登录");
            }
            sysOrder.setOrderStatus(4);
            sysOrder.setFinishTime(DateUtil.getSNowDateTime());
            orderMapper.updateByPrimaryKeySelective(sysOrder);
            return new Result(true,"操作成功");
        }
        return new Result(false,"订单状态不正确请刷新重试");
    }

    @Override
    public Result cancel(Integer orderId,Integer userId, String token)throws BusinessException {
        SysOrder sysOrder = orderMapper.selectByPrimaryKey(orderId);
        if(sysOrder.getOrderStatus()==1){
            SysCustomer customer = customerMapper.selectByPrimaryKey(userId);
            if(customer==null || StringUtils.isEmpty(customer.getMobile())){
                throw new BusinessException("请授权");
            }
            if(!token.equals(MD5Util.encode(customer.getMobile()))){
                throw new BusinessException("登录失效，请登录");
            }
            sysOrder.setOrderStatus(0);
            orderMapper.updateByPrimaryKeySelective(sysOrder);
            return new Result(true,"操作成功");
        }
        return new Result(false,"该订单暂时不能取消，请刷新重试");
    }

    @Override
    public String callBack(HttpServletRequest request, HttpServletResponse response)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)request.getInputStream()));
        String line = null;
        StringBuilder sb = new StringBuilder();
        while((line = br.readLine())!=null){
            sb.append(line);
        }
        Map map = PayCommonUtil.doXMLParse(sb.toString());
        logger.info("回调的map====="+map);
        String returnCode = map.get("return_code").toString();
        if(returnCode.equals("SUCCESS")){
            String resultCode = map.get("result_code").toString();
            if(resultCode.equals("SUCCESS")){
                SortedMap<String, Object> packageParams = new TreeMap<>();
                packageParams.put("appid", map.get("appid").toString());
                packageParams.put("bank_type", map.get("bank_type").toString());
                packageParams.put("cash_fee", map.get("cash_fee").toString());
                //如果有用支付红包的情况
                if(map.get("coupon_count")!=null){
                    packageParams.put("coupon_count",map.get("coupon_count").toString());
                }
                if(map.get("coupon_fee_0")!=null){
                    packageParams.put("coupon_fee_0",map.get("coupon_fee_0").toString());
                }
                if(map.get("coupon_id_0")!=null){
                    packageParams.put("coupon_id_0",map.get("coupon_id_0").toString());
                }
                if(map.get("coupon_fee")!=null){
                    packageParams.put("coupon_fee",map.get("coupon_fee").toString());
                }
                packageParams.put("fee_type", map.get("fee_type").toString());
                packageParams.put("is_subscribe", map.get("is_subscribe").toString());
                packageParams.put("mch_id", map.get("mch_id").toString());
                packageParams.put("nonce_str", map.get("nonce_str").toString());
                packageParams.put("openid", map.get("openid").toString());
                packageParams.put("out_trade_no", map.get("out_trade_no").toString());
                packageParams.put("result_code", map.get("result_code").toString());
                packageParams.put("return_code", map.get("return_code").toString());
                packageParams.put("time_end", map.get("time_end").toString());
                packageParams.put("total_fee", map.get("total_fee").toString());
                packageParams.put("trade_type", map.get("trade_type").toString());
                packageParams.put("transaction_id", map.get("transaction_id").toString());
                String sign = PayCommonUtil.createSign(packageParams);
                String originSign = map.get("sign").toString();
                if(sign.equals(originSign)){
                    //签名一致，保存支付流水
                    String xml="<xml>"
                            +"<return_code>SUCCESS</return_code>"
                            +"<return_msg>OK</return_msg>"
                            +"</xml>";
                    //logger.info(xml);
                    String orderNo = map.get("out_trade_no").toString();
                    String openId = map.get("openid").toString();
                    String tradeNo = map.get("transaction_id").toString();
                    SysOrder sysOrder = orderMapper.selectByOrderNo(orderNo);
                    sysOrder.setOrderStatus(2);
                    sysOrder.setTradeNo(tradeNo);
                    sysOrder.setPayTime(DateUtil.getSNowDateTime());
                    if(orderMapper.updateByPrimaryKeySelective(sysOrder)==1){
                        return xml;
                    }
                    return "<xml>"
                            +"<return_code>FAIL</return_code>"
                            +"<return_msg>处理失败</return_msg>"
                            +"</xml>";
                }else{
                    String xml="<xml>"
                            +"<return_code>FAIL</return_code>"
                            +"<return_msg>签名不一致</return_msg>"
                            +"</xml>";
                    logger.info(xml);
                    return xml;
                }
            }else{
                String xml="<xml>"
                        +"<return_code>FAIL</return_code>"
                        +"<return_msg>签名不一致</return_msg>"
                        +"</xml>";
                logger.info(xml);
                return xml;
            }
        }else{
            String xml="<xml>"
                    +"<return_code>SUCCESS</return_code>"
                    +"<return_msg>OK</return_msg>"
                    +"</xml>";
            logger.info(xml);
            return xml;
        }
    }

    @Override
    public Result myInfo(Integer page, Integer pageSize, Integer userId,String token) throws BusinessException{
        SysCustomer customer = customerMapper.selectByPrimaryKey(userId);
        if(customer==null || StringUtils.isEmpty(customer.getMobile())){
            throw new BusinessException("请授权");
        }
        if(!token.equals(MD5Util.encode(customer.getMobile()))){
            throw new BusinessException("非法请求");
        }
        PageHelper.startPage(page, pageSize);
        PageHelper.orderBy("create_time desc");
        List<SysInformation> info = informationMapper.myFollow(userId);
        return new Result(new PageInfo<>(info));
    }

    @Override
    public Result infoStar(StartForm startForm, String token)throws BusinessException {
        SysCustomer customer = customerMapper.selectByPrimaryKey(startForm.getUserId());
        if(customer==null || StringUtils.isEmpty(customer.getMobile())){
            throw new BusinessException("请授权");
        }
        if(!token.equals(MD5Util.encode(customer.getMobile()))){
            throw new BusinessException("非法请求");
        }
        if(startForm.getOperateType()==0) {
            SysUserStar sysUserStar = userStarMapper.selectByUserInfo(startForm.getUserId(), startForm.getInfoId());
            if (sysUserStar != null){
                sysUserStar.setIsDelete(1);
                userStarMapper.updateByPrimaryKeySelective(sysUserStar);
                return new Result(true,"操作成功");
            }
        }else{
            SysInformation information = informationMapper.selectByPrimaryKey(startForm.getInfoId());
            SysUserStar sysUserStar = userStarMapper.selectByUserInfo(startForm.getUserId(), startForm.getInfoId());
            if(sysUserStar==null){
                information.setStartUser(information.getStartUser()+1);
                sysUserStar = new SysUserStar();
                sysUserStar.setUserId(startForm.getUserId());
                sysUserStar.setInfoId(startForm.getInfoId());
                sysUserStar.setIsDelete(0);
                sysUserStar.setCreateTime(DateUtil.getSNowDateTime());
                userStarMapper.insertUseGeneratedKeys(sysUserStar);
            }
            information.setStartNum(information.getStartNum()+1);
            informationMapper.updateByPrimaryKeySelective(information);
        }
        return new Result(true,"操作成功");
    }

    private Result executeTwoWord(String name)throws BusinessException{
        char[] chars = name.toCharArray();
        String firstName = NameChangeUtil.getPinyin(chars[0]);
        String secondName = NameChangeUtil.getPinyin(chars[1]);
        Map<String, Map<String, String>> constantMap = DictInit.constantMap;
        Map<String,Object> result = new HashMap();
        result.put("name",name);
        if(StringUtils.isNotEmpty(firstName) && StringUtils.isNotEmpty(secondName)){
            Map<String, String> pinyinMap = constantMap.get(SurnameConstants.PINYIN);
            Map<String, String> elementGroup = constantMap.get(SurnameConstants.ELEMENT_GROUP);
            StringBuffer sb = new StringBuffer();
            String f = firstName.substring(0, 1);
            String s = secondName.substring(0, 1);
            sb.append(pinyinMap.get(f)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(f));
            sb.append(pinyinMap.get(s)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(s));
            sb.append(pinyinMap.get(s)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(s));
            result.put("element",sb.toString());
            List<SysExplain> group = explainMapper.findByGroup(elementGroup.get(sb.toString()));
            if(group.size()>0){
                result.put("explainType",group.get(0).getGroupName());
                Map<String,List<SysExplain>> explainMap = new HashMap<>();
                for (SysExplain sysExplain : group) {
                    List<SysExplain> list = explainMap.get(sysExplain.getExplainType());
                    if(list==null){
                        list = new ArrayList<>();
                    }
                    list.add(sysExplain);
                    explainMap.put(sysExplain.getExplainType(),list);
                }
                result.put("explainResult",explainMap);
            }
        }
        return new Result(result);
    }
    private Result executeThreeWord(String name)throws BusinessException{
        Map<String, Map<String, String>> constantMap = DictInit.constantMap;
        Map<String, String> repeatName = constantMap.get(SurnameConstants.REPEAT_SURNAME);
        Map<String, String> pinyinMap = constantMap.get(SurnameConstants.PINYIN);
        Map<String, String> elementGroup = constantMap.get(SurnameConstants.ELEMENT_GROUP);
        Map<String,Object> result = new HashMap();
        result.put("name",name);
        StringBuffer sb = new StringBuffer();
        char[] chars = name.toCharArray();
        String firstName = NameChangeUtil.getPinyin(chars[0]);
        String secondName = NameChangeUtil.getPinyin(chars[1]);
        String thirdName = NameChangeUtil.getPinyin(chars[2]);
        //判断名字是不是复姓
        if(repeatName.get(name.substring(0,2))!=null){
            sb.append(repeatName.get(name.substring(0,2)));
            String t = thirdName.substring(0, 1);
            sb.append(pinyinMap.get(t)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(t));
            sb.append(pinyinMap.get(t)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(t));
        }else{
            String f = firstName.substring(0, 1);
            String s = secondName.substring(0, 1);
            String t = thirdName.substring(0, 1);
            sb.append(pinyinMap.get(f)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(f));
            sb.append(pinyinMap.get(s)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(s));
            sb.append(pinyinMap.get(t)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(t));
        }
        result.put("element",sb.toString());
        List<SysExplain> group = explainMapper.findByGroup(elementGroup.get(sb.toString()));
        if(group.size()>0){
            result.put("explainType",group.get(0).getGroupName());
            Map<String,List<SysExplain>> explainMap = new HashMap<>();
            for (SysExplain sysExplain : group) {
                List<SysExplain> list = explainMap.get(sysExplain.getExplainType());
                if(list==null){
                    list = new ArrayList<>();
                }
                list.add(sysExplain);
                explainMap.put(sysExplain.getExplainType(),list);
            }
                result.put("explainResult",explainMap);
        }
        return new Result(result);
    }
    private Result executeFourthWord(String name)throws BusinessException{
        Map<String, Map<String, String>> constantMap = DictInit.constantMap;
        Map<String, String> repeatName = constantMap.get(SurnameConstants.REPEAT_SURNAME);
        Map<String, String> pinyinMap = constantMap.get(SurnameConstants.PINYIN);
        Map<String, String> elementGroup = constantMap.get(SurnameConstants.ELEMENT_GROUP);
        Map<String,Object> result = new HashMap();
        result.put("name",name);
        StringBuffer sb = new StringBuffer();
        char[] chars = name.toCharArray();
        String firstName = NameChangeUtil.getPinyin(chars[0]);
        String secondName = NameChangeUtil.getPinyin(chars[2]);
        String thirdName = NameChangeUtil.getPinyin(chars[3]);
        String fourName = NameChangeUtil.getPinyin(chars[1]);
        //判断名字是不是复姓
        if(repeatName.get(name.substring(0,2))!=null){
            sb.append(repeatName.get(name.substring(0,2)));
            String s = secondName.substring(0, 1);
            String t = thirdName.substring(0, 1);
            sb.append(pinyinMap.get(s)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(s));
            sb.append(pinyinMap.get(t)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(t));
        }else{
            String f = firstName.substring(0, 1);
            String s = fourName.substring(0, 1);
            String t = thirdName.substring(0, 1);
            sb.append(pinyinMap.get(f)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(f));
            sb.append(pinyinMap.get(s)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(s));
            sb.append(pinyinMap.get(t)==null?SurnameConstants.DEFAULT_ELEMENT:pinyinMap.get(t));
        }
        result.put("element",sb.toString());
        List<SysExplain> group = explainMapper.findByGroup(elementGroup.get(sb.toString()));
        if(group.size()>0){
            result.put("explainType",group.get(0).getGroupName());
            Map<String,List<SysExplain>> explainMap = new HashMap<>();
            for (SysExplain sysExplain : group) {
                List<SysExplain> list = explainMap.get(sysExplain.getExplainType());
                if(list==null){
                    list = new ArrayList<>();
                }
                list.add(sysExplain);
                explainMap.put(sysExplain.getExplainType(),list);
            }
            result.put("explainResult",explainMap);
        }
        return new Result(result);
    }

    private String getOrderNo(){
        String cday = DateUtil.getSNowDate();
        long incr ;
        if(redisUtil.get(cday)!=null){
            incr = redisUtil.incr(cday, 1);
        }else{
            redisUtil.set(cday,1);
            incr = 1;
        }
        return DateUtil.getSNowDateTimeDB() + incr;
    }
}
